import Mock from 'mockjs';

import { prefixAPI } from '@/config/global';
import { SUCCESS_CODE } from '@/constants';

const { Random } = Mock;

const listItem = {
  id: '@id',
  sn: /^[A-Za-z0-9]{12}$/,
  dev_name: '@cword(5,10)',
  deviceName: '@cword(5,10)',
  enable: '@boolean()',
  type: '@integer(1, 3)',
  network: {
    id: '@id',
    type: '@integer(1, 2)',
    open: '@boolean()',
    connect_type: '@integer(1, 2)',
    connect_status: '@boolean()',
    ipv4: '192.168.4.64',
    subnet: '255.255.255.0',
    default: '192.168.2.1',
    dns: '192.168.2.1'
  },
  number: '@id',
  videoUrl: 'rtsp：192.138.101.12:554/stream/dsffajk/hgfjdhjgfjnh/vmcxvnjsfb',
  equipmentId: '@id',
  equipment: {
    id: '@id',
    name: '@cword(5,10)',
    type: '@integer(1, 4)',
    model: 'IPC-@integer(1000, 1999)',
    number: '@id',
    address: `${Random.province()}-${Random.city()}-${Random.county()}`,
    uodateTime: Random.datetime('yyyy-MM-dd HH:mm:ss'),
  },
  video: {
    id: '@id',
    type: '@integer(1, 3)',
    url: 'rtsp：192.138.101.12:554/stream/dsffajk/hgfjdhjgfjnh/vmcxvnjsfb',
    transportProtocol: 'TCP',
    encodingFormat: 'H.265',
    decodingFormat: 'NV12',
    compressionFormat: 'HEVC',
  },
  output: [
    {
      deviceName: 'GA1400',
      status: 1,
      connect: 1,
      deviceId: '@id',
    },
    {
      deviceName: 'GB28181',
      status: 2,
      connect: 2,
      deviceId: '@id',
    },
  ],
  capture: {
    face: {
      id: '@id',
      name: '',
      num: '76.5%',
      address: `${Random.province()}-${Random.city()}-${Random.county()}`,
      create_at: Random.datetime('yyyy-MM-dd HH:mm:ss'),
    },
  },
};

export default [
  {
    url: `${prefixAPI}/mock/list`,
    method: 'get',
    timeout: 1000,
    response: () => ({
      ...Mock.mock({
        code: SUCCESS_CODE,
        msg: 'string',
        data: {
          total: 30,
          'list|30': [listItem],
        },
      }),
    }),
  },
  {
    url: `${prefixAPI}/mock/create`,
    method: 'post',
    timeout: 2000,
    response: () => ({
      ...Mock.mock({
        code: SUCCESS_CODE,
        msg: 'string',
        data: {},
      }),
    }),
  },
  {
    url: `${prefixAPI}/mock/update`,
    method: 'post',
    timeout: 2000,
    response: () => ({
      ...Mock.mock({
        code: SUCCESS_CODE,
        msg: 'string',
        data: {},
      }),
    }),
  },
  {
    url: `${prefixAPI}/mock/del`,
    method: 'post',
    timeout: 2000,
    response: () => ({
      ...Mock.mock({
        code: SUCCESS_CODE,
        msg: 'string',
        data: {},
      }),
    }),
  },
  {
    url: `${prefixAPI}/mock/info`,
    method: 'get',
    timeout: 1000,
    response: () => ({
      ...Mock.mock({
        code: SUCCESS_CODE,
        msg: 'string',
        data: { ...listItem },
      }),
    }),
  },
];
